{include file="public/header"}

<body>

	<section id="container" class="">
		<!--header start-->
		{include file="public/headtop" /}
		<!--header end-->
		<!--sidebar start-->
		<aside>
			<div id="sidebar"  class="nav-collapse ">
				<!-- sidebar menu start-->
				{include file="public/menu" /}
				<!-- sidebar menu end-->
			</div>
		</aside>
		<!--sidebar end-->
		<!--main content start-->
		<section id="main-content">
			<section class="wrapper site-min-height">
				<!-- page start-->
				<div class="row">
					<div class="col-lg-12">
						{include file="public/nav" webnavname="兑换码管理"}
					</div>
					<div class="col-lg-6">
						<button id="editable-sample_new" class="btn green success" data-toggle="modal" href="#incRedeem">
							生成兑换码 <i class="fa fa-plus"></i>
						</button>
					</div>
					<div class="col-lg-6">
						<input type="text"  class="form-control medium" id="search" placeholder="搜索兑换码，全部请为空">
					</div>
					
					<div class="col-lg-12">
						
						<section class="panel">
							<header class="panel-heading">
								兑换码列表
							</header>
							<div class="panel-body">
								<table class="table table-striped table-advance table-hover">
									<thead>
										<tr>
											<th>兑换码</th>
											<th><i class="fa fa-rmb"></i> 金额</th>
											<th class="hidden-phone"><i class="fa fa-clock"></i> 生成时间</th>
											<th class="hidden-phone"><i class="fa fa-clock"></i> 兑换时间</th>
											<th><i class="fa fa-users"></i> 兑换用户名</th>
											<th><i class="fa fa-edit"></i> 状态</th>
											<th><i class="fa fa-edit"></i> 操作</th>
										</tr>
									</thead>
									<tbody>
										{volist name="redeemList" id="redeem"}
										<tr id="redeem_{$redeem.id}">
											<td>{$redeem.redeem}</td>
											<td>{$redeem.money}</td>
											<td class="hidden-phone">{$redeem.ctime}</td>
											<td class="hidden-phone">{$redeem.etime}</td>
											<td>{$redeem.username}</td>
											<td>{$redeem.status ? '未使用' : '已使用'}</td>
											<td><a href="javascript:del({$redeem.id})">删除</a></td>
										</tr>
										{/volist}

									</tbody>
								</table>
								<div class="text-center">
									{$pageNum}
								</div>
							</div>

						</section>
					</div>
				</div>
				<div class="row">
					<div class="col-lg-12">
						<section class="panel">
							<div class="panel-body">
								<div class="modal fade" id="EchoMsg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
									<div class="modal-dialog modal-sm">
										<div class="modal-content-wrap">
											<div class="modal-content">
												<div class="modal-header">
													<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
													<h4 class="modal-title">消息通知</h4>
												</div>
												<div class="modal-body text-center" id="msgVal">

												</div>
												<div class="modal-footer">
													<button class="btn btn-danger" type="button" data-dismiss="modal"> OK</button>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</section>
					</div>
				</div>
				<div class="modal fade  modal-dialog-center" id="incRedeem" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content-wrap">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
									<h4 class="modal-title">新增兑换码</h4>
								</div>
								<div class="modal-body">

									<form role="form">
										<div class="form-group">
											<label>金额</label>
											<div class="iconic-input">
												<i class="fa fa-user"></i>
												<input type="number" class="form-control" name="money" id="money" placeholder="金额">
											</div>
										</div>
										<div class="form-group">
											<label>数量</label>
											<div class="iconic-input">
												<i class="fa fa-unlock-alt"></i>
												<input type="number" class="form-control" name="number" id="number" placeholder="数量">
											</div>
										</div>
									</form>

								</div>
								<div class="modal-footer">
									<button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
									<button class="btn btn-warning" type="button" onclick="inc()"> 新增</button>
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- page end-->
			</section>
		</section>
		<!--main content end-->
		<!-- Right Slidebar start -->
		{include file="public/slidright"}
		<!-- Right Slidebar end -->
		<!--footer start-->
		<footer class="site-footer">
			{include file="public/footer"}
		</footer>
		<!--footer end-->
	</section>

	<!-- js placed at the end of the document so the pages load faster -->
	<script src="__STATIC__/js/jquery.js"></script>
	<script src="__STATIC__/js/bootstrap.min.js"></script>
	<script class="include" type="text/javascript" src="__STATIC__/js/jquery.dcjqaccordion.2.7.js"></script>
	<script src="__STATIC__/js/jquery.scrollTo.min.js"></script>
	<script src="__STATIC__/js/jquery.nicescroll.js" type="text/javascript"></script>
	<script src="__STATIC__/js/respond.min.js" ></script>

	<!--right slidebar-->
	<script src="__STATIC__/js/slidebars.min.js"></script>


	<!--common script for all pages-->
	<script src="__STATIC__/js/common-scripts.js"></script>

	<script type="text/javascript">
		function del(id){
			$.post('', {id: id,type:'del'}, function(data, textStatus, xhr) {
				if(data.code==200){
					$("#redeem_"+id).remove();
					EchoMsg(data.msg);
				}else{
					EchoMsg('删除失败：'+data.msg);
				}
			});
		}
		function EchoMsg(msg,local){
			$('#msgVal').html(msg);
			$('#EchoMsg').modal('show');
			if(local){
				$('#EchoMsg').on('hidden.bs.modal', function () {
					window.location.href = local;
				})
			}
		}
		$(function() {
			$('#search').on('keypress',function(event){
				if(event.keyCode == "13"){  
					window.location.href="?search="+$('#search').val();
				}
			});
		});

		function inc(){
			$('#incRedeem').modal('hide');
			var money = $('#money').val();
			var number = $('#number').val();
			if(money==''||number==''){
				EchoMsg('所有项不能为空');
				return false;
			}
			$.post('',{money:money,number:number,type:'inc'},function(data){
				if(data.code==200){
					EchoMsg(data.msg,'/admin/redeem.html');
				}else{
					EchoMsg('Error:'+data.msg,'/admin/redeem.html');
				}
			})
			
		}
	</script>
</body>
</html>